﻿public class ClasseDTO : IEquatable<ClasseDTO>
{
	public int Id { get; set; }
    public string Nome { get; set; }
    public bool Stato { get; set; }

    public override int GetHashCode()
    {
        int hashCode = 10;

        hashCode += this.Id.GetHashCode();
        hashCode += this.Nome.GetHashCode();
        hashCode += this.Stato.GetHashCode();

        return hashCode;
    }

    public bool Equals(ClasseDTO other)
    {
        if (other != null)
            return this.GetHashCode() == other.GetHashCode();
        return false;
    }
	
	public bool getDiff(IEnumerable<ClasseDTO> list1, IEnumerable<ClasseDTO> list2, out Dictionary<int, int> diff)
    {
        diff = new Dictionary<int, int>();
        var temp = new Dictionary<int, ClasseDTO>();
        bool ret = true;

        try
        {
			//get all element from list1 and initialize the map of difference
            foreach (ClasseDTO e in list1)
            {
                diff.Add(e.IdRit, -1);
                temp.Add(e.IdRit, e);
            }

			//fetch all element from list2
            foreach (ClasseDTO e in list2)
            {
				//if the map contain the current element
                if (diff.ContainsKey(e.IdRit))
					//a comparison is made between the two elements and if they are equal in the map will be inserted the value 0
                    if (temp[e.IdRit].Equals(e))
                        diff[e.IdRit]++;
					//otherwise it is inserted into the map a value of 1, and the return value is set to false
                    else
                    {
                        diff[e.IdRit] += 2;
                        ret = false;
                    }
				//otherwise it means that it is a new element that is added to the map with value 2, and the return value is set to false
                else
                {
                    diff.Add(e.IdRit, 2);
                    ret = false;
                }
            }

			//if there is an element of the map with value -1, the return value is set to false
            if (diff.Count(c => c.Value == -1) > 0) ret = false;

            return ret;
        }
        catch (Exception ex)
        {
            diff = null;
            return false;
        }
    }
}